package org.jeecg.modules.online.cgform.enhance.impl;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Excel导入增强，针对导入数据进行check或者数据转换
 */
@Slf4j
@Component("cgformEnhanceImportDemo")
public class CgformEnhanceImportDemo implements CgformEnhanceJavaInter{

	@Override
	public int execute(String tableName, JSONObject json) throws BusinessException {
//		log.info("--------我是自定义java增强测试bean 导入示例-----------");
		log.info("--------当前tableName=>"+tableName);
		log.info("===============================================================================================================");
		log.info("--------导入JSON数据=>"+json.toJSONString());

		if(oConvertUtils.isEmpty(json.get("name"))){
			log.info("-----变更导入数据，直接返回1----");
			json.put("name","默认值");
			return 1;
		}

		if(json.getString("name").equals("error")){
			json.put("name","默认值");
			throw new BusinessException("测试抛出异常error");
		}

		if(json.getString("name").equals("hello")){
			log.info("-----导入数据变更新，直接返回2----");
			json.put("id","testid123");
			json.put("name","JAVA导入增强 测试修改");
			return 2;
		}

		if(json.getString("name").equals("ok")){
			log.info("-----丢弃导入数据，直接返回0----");
			// 如果丢弃数据，直接返回0
			return 0;
		}
		//业务代码
		return 1;
	}


	@Override
	public int execute(String tableName, Map<String, Object> map) throws BusinessException {
		return 1;
	}

}
